﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace User
{
    public class Account : INotifyPropertyChanged
    {
#pragma warning disable IDE1006 // 命名样式
        [JsonIgnore]
        private string _name;
        public string name{ get=>_name; set
            {
                _name = value;
                NotifyPropertyChanged();
            }
        }
        public string password { get; set; }

        [JsonIgnore]
        private Right _right;
        [JsonConverter(typeof(StringEnumConverter))]//枚举序列化时以字符串形式存储
        public Right right
        {
            get => _right; set
            {
                _right = value;
                NotifyPropertyChanged();
            }
        }
        public string key { get; set; }
        
        public event PropertyChangedEventHandler PropertyChanged;
        // This method is called by the Set accessor of each property.
        // The CallerMemberName attribute that is applied to the optional propertyName
        // parameter causes the property name of the caller to be substituted as an argument.
        private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
#pragma warning restore IDE1006 // 命名样式
    }
    public enum Right
    {
        None,
        Normal,
        Administrator,
        Ruler
    }
}
